package cac.fenjian.resource.msbinpartbasic.service;

import cac.fenjian.resource.MsBinPartBasic.dto.MsBinPartBasicDTO;
import cac.fenjian.resource.msbinpartbasic.dao.MsBinPartBasicDao;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.QueryRespBean;
import com.cac.dme.adapter.utils.PageHelper;
import com.cac.dme.common.exception.service.DaoException;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MsBinPartBasicService {
    @Autowired
    private MsBinPartBasicDao msBinPartBasicDao;

    /**
     * 按照条件分页查询
     * @param queryReqBean
     * @param orderBy
     * @return
     */
    @Transactional(readOnly = true)
    public QueryRespBean<MsBinPartBasicDTO> searchMsBinPartBasicByPage(QueryReqBean<MsBinPartBasicDTO> queryReqBean, String orderBy){
        QueryRespBean<MsBinPartBasicDTO> queryRespBean = new QueryRespBean<>();
        try{
            PageHelper.startPage(queryReqBean.getPageParameter());
            MsBinPartBasicDTO searchParams = queryReqBean.getSearchParams();
            Page<MsBinPartBasicDTO> dataList = msBinPartBasicDao.searchMsBinPartBasicByPage(searchParams,orderBy,queryReqBean.getKeyWord());
            queryRespBean.setResult(dataList);
            return queryRespBean;
        }catch (Exception e){
            throw  new DaoException(e.getMessage(),e);
        }
    }
    /**
     * 根据条件查询数据
     * @param queryReqBean
     * @return
     */
    public List<MsBinPartBasicDTO> searchMsBinPartByParams(QueryReqBean<MsBinPartBasicDTO> queryReqBean){
        try{
            return msBinPartBasicDao.searchMsBinPartByParams(queryReqBean.getSearchParams());
        }catch (Exception e){
            throw new  DaoException(e.getMessage(),e);
        }
    }
    /**
     * 通过主键查询单条记录
     *
     * @param id 主键id
     * @return MsBinPartBasicDTO
     */
    @Transactional
    public MsBinPartBasicDTO findMsBinPartBasicById(String id) {
        try {
            MsBinPartBasicDTO msBinPartBasicDTO = msBinPartBasicDao.findMsBinPartBasicById(id);
            //记录日志
            if (msBinPartBasicDTO != null) {
            }
            return msBinPartBasicDTO;
        } catch (Exception e) {
            throw new DaoException(e.getMessage(), e);
        }
    }
}
